<template>
    <div class="chat-container">
      <el-divider></el-divider>
      <div class="chat-window">
        <ul class="messages">
          <li v-for="message in messages" :key="message.id" class="message" :class="{ 'user-message': message.isUserMessage }">
            {{ message.text }}
          </li>
        </ul>
      </div>
      <div class="input-container">
        <input type="text" v-model="inputText" @keyup.enter="sendMessage" placeholder="请输入消息" class="input-text">
        <button @click="sendMessage" class="send-button">发送</button>
      </div>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        inputText: '',
        messages: [],
      };
    },
    methods: {
      sendMessage() {
        if (this.inputText.trim() !== '') // 检查输入框中是否有文本
          this.messages.push({ text: this.inputText, isUserMessage: true });
        this.inputText = '';
  
        setTimeout(() => {
          this.messages.push({ text: '已接收到反馈', isUserMessage: false });
        }, 500);
      },
    },
  };
  </script>
  
  <style scoped>
  .chat-container {
    max-width: 800px;
    margin: 0 auto;
    margin-left: 300px;
  }
  
  .chat-window {
    margin-top: 20px;
    height: 300px;
    overflow-y: scroll;
    border: 1px solid #ccc;
    padding: 10px;
    background-color: #f5f5f5;
  }
  
  .messages {
    list-style-type: none;
    padding: 0;
    margin: 0;
  }
  
  .message {
    margin-bottom: 10px;
    padding: 8px;
    border-radius: 5px;
  }
  
  .user-message {
    background-color: #e2f0cb;
    float: right;
  }
  
  .input-container {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
  }
  
  .input-text {
    flex: 1;
    padding: 8px;
    border-radius: 5px;
    border: 1px solid rgb(177, 196, 202);
  }
  
  .send-button {
    padding: 8px 15px;
    border: none;
    border-radius: 5px;
    background-color: #4caf50;
    color: #fff;
    cursor: pointer;
  }
  
  .select-text {
    padding-top: 10px;
  }
  </style>